
import { MiddlewareConsumer, Module, NestModule, RequestMethod } from '@nestjs/common';
import { UploadService } from './upload.service';
import { UploadController } from './upload.controller';
import { Logger } from '../middleware/index';
import { MulterModule } from '@nestjs/platform-express/multer';
import { diskStorage } from 'multer';
import { extname, join } from 'path';
console.log(join(__dirname, '../images'),'join(__dirname,   ')
import { ConfigModule, ConfigService } from '@nestjs/config';
@Module({
  controllers: [UploadController],
  imports: [MulterModule.register({
    storage: diskStorage({
      destination: join(__dirname, '../../../../images'),
      filename: (_, file, callback) => {
        const filename = `${new Date().getTime() + extname(file.originalname)}`
        return callback(null,filename)
      }
    })
  }),ConfigModule],
  providers: [UploadService,ConfigService],
  
})
export class UploadModule implements NestModule {
  configure(consumer: MiddlewareConsumer) {
    consumer.apply(Logger).forRoutes({
      path: 'album',
      method: RequestMethod.POST
    })
  }
}
